<template>
  <div class="news-item">
    <router-link class="item" v-if="!itemData.url" :to="{name: 'news-detail', params:{id: itemData.newsID}}">
      <div class="cover" :style="{backgroundImage:`url(${itemData.imageUrl})`}"></div>
      <div class="content-box">
        <h3 class="title">{{itemData.title}}</h3>
        <div class="info"><span class="author">网易体育</span> <span class="views">2894阅读</span>{{itemData.create_at | formateDate}}</div>
      </div>
    </router-link>
    <a v-else class="item"  :href="itemData.url">
      <div class="cover" :style="{backgroundImage:`url(${itemData.imageUrl})`}"></div>
      <div class="content-box">
        <h3 class="title">{{itemData.title}}</h3>
        <div class="info"><span class="author">网易体育</span> <span class="views">2894阅读</span>{{itemData.create_at | formateDate}}</div>
      </div>
    </a>
  </div>
</template>

<script>
import dayjs from 'dayjs'
export default {
  props: {
    itemData: Object
  },
  filters: {
    formateDate (time) {
      return dayjs(dayjs.unix(time)).format('YYYY-M-D')
    }
  }
}
</script>

<style scoped lang="less">
.news-item {
  .item{
    display: flex;
    align-items: center;
    // box-shadow: 0px 0px 17.64px 0.36/2px rgba(44, 44, 44, 0.09);
    border-radius: 5px;
    margin: 7.5px 0;
  }
  .cover{
    width: 209/2px;
    height: 139/2px;
    flex: 0 0 209/2px;
    background-repeat: no-repeat;
    background-position: center center;
    background-size: cover;
    border-radius: 5px;
  }
  .content-box{
    flex: 1;
    width: 0;
    margin-left: 12px;
  }
  .title {
    font-size: 28/2px;
    line-height: 19px;
    color: #353434;
    margin: 0;
    margin-bottom: 15px;
    .line-overflow(2);
  }
  .content,.info {
    font-size: 22/2px;
    color: #939393;
    line-height: 14px;
  }
  .author,.views{
    margin-right: 10px;
  }
}

</style>
